﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using PointOfSale.Global;
using PointOfSale.Report.Stock;
using System.Data.SqlClient;

namespace PointOfSale
{
	/// <summary>
	/// Summary description for frmDepartmentWiseReOrderReport.
	/// </summary>
	public class frmDepartmentWiseReOrderReport : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnReport;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.LookupComboBox cboDepartment;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.PictureBox pictureBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmDepartmentWiseReOrderReport()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmDepartmentWiseReOrderReport));
			this.btnClose = new System.Windows.Forms.Button();
			this.btnReport = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.cboDepartment = new System.Windows.Forms.LookupComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btnClose
			// 
			this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnClose.Location = new System.Drawing.Point(272, 120);
			this.btnClose.Name = "btnClose";
			this.btnClose.TabIndex = 3;
			this.btnClose.Text = "Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnReport
			// 
			this.btnReport.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnReport.Location = new System.Drawing.Point(192, 120);
			this.btnReport.Name = "btnReport";
			this.btnReport.TabIndex = 2;
			this.btnReport.Text = "Report";
			this.btnReport.Click += new System.EventHandler(this.btnReport_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.cboDepartment);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(112, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(233, 96);
			this.groupBox1.TabIndex = 17;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Select Department";
			this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
			// 
			// cboDepartment
			// 
			this.cboDepartment.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.cboDepartment.Location = new System.Drawing.Point(80, 40);
			this.cboDepartment.Name = "cboDepartment";
			this.cboDepartment.Size = new System.Drawing.Size(144, 21);
			this.cboDepartment.TabIndex = 1;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "Department";
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(8, 16);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(104, 96);
			this.pictureBox1.TabIndex = 20;
			this.pictureBox1.TabStop = false;
			// 
			// frmDepartmentWiseReOrderReport
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(352, 158);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnReport);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.pictureBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmDepartmentWiseReOrderReport";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Department Wise Re Order Report";
			this.Load += new System.EventHandler(this.frmDepartmentWiseReorderReport_Load);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void groupBox1_Enter(object sender, System.EventArgs e)
		{
		
		}

		private void frmDepartmentWiseReorderReport_Load(object sender, System.EventArgs e)
		{
			string SQL = "SELECT DepartmentName FROM tblDepartment";			
			SqlCommand thisCommand = new SqlCommand(SQL,clsGlobal.g_DataConn);						
			SqlDataReader dr = thisCommand.ExecuteReader();
			// begin read
			while(dr.Read())
			{
				cboDepartment.Items.Add(dr.GetValue(0));
			}
			dr.Close();	
			cboDepartment.Focus();	
		}

		private void btnReport_Click(object sender, System.EventArgs e)
		{
			DialogResult result;
			//Kiểm tra Department nhập vào			
			// Kiểm tra xem có tồn tại Department nhập vào trong co sở dữ liệu không 
			DataSet ds;
			ds = new DataSet ();			
			ds = clsGlobal.Db.GetDataToDataSet("SELECT DepartmentName FROM tblDepartment WHERE (DepartmentName = '" + cboDepartment.Text.ToString().Trim() + "') ",clsGlobal.g_DataConn,"tblDepartment");
			if (ds.Tables ["tblDepartment"].Rows.Count == 0)
			{
				result = MessageBox.Show ("Không có Department nhập vào  !\nHãy nhập lại !","Thong bao",MessageBoxButtons.OK,MessageBoxIcon.Question);			
			}
			else 
			{
				// Hien Report 
				frmReportReorderStock frmOS = new frmReportReorderStock(); 
				
				//PointOfSale.frmPOSTransaction frmOS = new PointOfSale.frmPOSTransaction();				
				frmOS.strDiaDiem = cboDepartment.Text.ToString().Trim();				
				frmOS.ShowDialog();
			}
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}
